package org.xutils.main;

import android.app.Application;

import com.zzh.lib.core.HLibrary;

import org.xutils.db.DbManager;
import org.xutils.db.ex.DbException;
import org.xutils.db.log.Log;
import org.xutils.db.table.TableEntity;
import org.xutils.db.xDb;

/**
 * Created by ZZH on 4/20/21.
 *
 * @Date: 4/20/21
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class App extends Application {

    public DbManager mDbManager;

    private static App mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        HLibrary.getInstance().init(this);
        HLibrary.setDebug(true);
        xDb.getInstance().init(mInstance);
        Log.getInstance().setDebug(true);
        Log.getInstance().setDebugLogCreate(true);
        Log.getInstance().setDebugLogInsert(true);
        Log.getInstance().setDebugLogAlter(true);
        Log.getInstance().setDebugLogDDL(true);
        Log.getInstance().setDebugLogQuery(true);
        Log.getInstance().setDebugLogUpdate(true);
        Log.getInstance().setDebugLogDelete(true);

        Log.getInstance().init(new LogDB());
        DbManager.DaoConfig config = new DbManager.DaoConfig()
                .setDbName("zzh.db")
                .setAllowTransaction(true)
                .setAllowErrorEndTransaction(true)
                .setDbVersion(2)
                .setDbEncrypt("")
                .setTableCreateListener(new DbManager.TableCreateListener() {
                    @Override
                    public void onTableCreated(DbManager db, TableEntity<?> table) {
                        Log.getInstance().e("创建表：" + table.getName());
                    }
                });
        try {
            mDbManager = xDb.getDb(config);
        } catch (DbException e) {
            e.printStackTrace();
        }

    }

    public static App getInstance() {
        return mInstance;
    }

    public DbManager getDbManager() {
        return mDbManager;
    }
}
